local skill = fk.CreateSkill {
  name = "ym__life_death_skill",
}
skill:addEffect("cardskill", {
    prompt = "#ym__life_death_skill",
    can_use = Util.CanUseToSelf,
    mod_target_filter = Util.TrueFunc,
    on_effect = function(self, room, effect)
        room:setBanner("life_death",1)
        p(room:getBanner("life_death"))
        while room:getBanner("life_death") == 1 do
            for _, target in ipairs(room:getOtherPlayers(effect.to)) do
                if not target.dead and room:getBanner("life_death") == 1 then
                    local other_players = table.filter(room:getOtherPlayers(target, false), function(p)
                        return not p:isRemoved()
                    end)
                    local luanwu_targets = table.filter(other_players, function(p2)
                        return table.every(other_players, function(p1)
                            return target:distanceTo(p1) >= target:distanceTo(p2)
                        end)
                    end)
                    local use = room:askToUseCard(target, {
                        pattern = "slash",
                        prompt = "#luanwu-use",
                        cancelable = true,
                        extra_data = {
                            exclusive_targets = table.map(luanwu_targets, Util.IdMapper),
                            bypass_times = true,
                        },
                        skill_name = skill.name,
                    })
                    if use then
                        use.extraUse = true
                        room:useCard(use)
                    else
                        room:loseHp(target, 1, skill.name)
                    end
                end
            end
        end
    end,
})
skill:addEffect(fk.Death, {
    global = true,
    can_refresh = function(self, event, target, player, data)
        return true
    end,
    on_refresh = function(self, event, target, player, data)
        player.room:setBanner("life_death",0)
    end
})
skill:addEffect(fk.AfterCardUseDeclared, {
    global = true,
    can_refresh = function(self, event, target, player, data)
        return data.card.trueName == "life_death"
    end,
    on_refresh = function(self, event, target, player, data)
        data.unoffsetableList = table.map(player.room.alive_players, Util.IdMapper)
    end
})

return skill